home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / memory / addram10.zip / SUBRAM.ASM < prev    next >
Assembly Source File  |  1989-02-14  |  7KB  |  232 lines

  1. ;   Copyright (c) 1989 by Marty Del Vecchio for personal use only.
  2. ;   May not be sold under any circumstances.  For questions call me
  3. ;   at (508) 820-1544, or the Channel 1 BBS at (617) 354-8873).
  4. ;
  5. ;   To create SUBRAM.COM, you must assemble this file:
  6. ;
  7. ;       MASM subram;
  8. ;
  9. ;   then link it to an executable:
  10. ;
  11. ;       LINK subram;
  12. ;
  13. ;   then turn it into a .COM file:
  14. ;
  15. ;       EXE2BIN sybram.exe subram.com
  16. ;
  17. ;   then delete the .EXE file:
  18. ;
  19. ;       DEL subram.exe
  20. ;
  21. ;
  22. get_vector      equ     35h
  23. emm_int         equ     67h
  24. EMM_name_length equ     8
  25.  
  26. code_seg_a      segment
  27.                 assume  cs:code_seg_a, ds:code_seg_a
  28.  
  29.                 org     100h
  30.  
  31. subram          proc    far
  32.  
  33. start:          jmp     begin
  34.  
  35. copyrt          db      0Dh, 0Ah
  36.                 db      'SUBRAM 1.00  Copyright (C) 1989 by Marty Del Vecchio', 0Dh, 0Ah, 00h
  37. have_640_msg    db      'Only 640KB DOS memory--no memory had been added by ADDRAM.', 0Dh, 0Ah, 00h
  38.  
  39. mem_reset_msg   db      'DOS memory reset to 640KB, EMS memory freed.', 0Dh, 0Ah, 00h
  40. no_EMM_msg      db      'Expanded Memory Manager not found--no EMS installed.', 0Dh, 0Ah, 00h
  41. no_name_msg     db      'No memory had been added by ADDRAM.', 0Dh, 0Ah, 00h
  42. not_last_msg    db      'This program''s memory allocation block is not the last', 0Dh, 0Ah
  43.                 db      'in DOS''s chain.  Cannot change memory if not at end.', 0Dh, 0Ah, 00h
  44. free_err_msg    db      'Error deallocating EMS memory.', 0Dh, 0Ah, 00h
  45.  
  46. EMM_name        db      'EMMXXXX0'
  47. handle_name     db      'ADDRAM00'      ; 8 characters, pad with 0
  48. handle          dw      0               ; EMS handle
  49. pages           dw      0               ; Number of pages owned by handle
  50.  
  51. begin:          call    say_hello       ; Print messages
  52.  
  53.                 call    check_640       ; See if already 640K
  54.                 jc      error_exit
  55.  
  56.                 call    check_EMM       ; Can we find our handle?
  57.                 jc      error_exit
  58.  
  59.                 call    check_MCB       ; Is MCB last in chain?
  60.                 jc      error_exit
  61.  
  62.                 call    tell_DOS        ; Convince DOS there is less memory
  63.                 jc      error_exit
  64.  
  65.                 call    free_handle     ; Free EMS handle and its pages
  66.                 jc      error_exit
  67.  
  68. success_exit:   mov     ax, 4C00h       ; Terminate, signal success
  69.                 int     21h
  70.  
  71. error_exit:     mov     ax, 4C01h       ; Terminate, signal failure
  72.                 int     21h
  73.  
  74. subram          endp
  75.  
  76.  
  77. say_hello       PROC    near
  78.                 mov     si, offset copyrt
  79.                 call    printf_si
  80.                 ret
  81. say_hello       ENDP
  82.  
  83.  
  84. check_640       PROC    near
  85.                 push    ds
  86.                 mov     ax, 40h         ; Accessing BIOS area
  87.                 mov     ds, ax
  88.                 mov     ax, ds:[0013h]  ; Get # of KB from BIOS
  89.                 pop     ds
  90.                 cmp     ax, 640         ; Is it 640K right now?
  91.                 je      is_640          ; Yes, error!
  92.  
  93. not_640:        clc                     ; No, signal OK
  94.                 jmp     check_640_exit
  95.  
  96. is_640:         mov     si, offset have_640_msg
  97.                 call    printf_si
  98.                 stc
  99.  
  100. check_640_exit: ret
  101. check_640       ENDP
  102.  
  103.  
  104. check_EMM       PROC    near
  105.                 mov     ah, get_vector          ; First check if EMM here
  106.                 mov     al, emm_int
  107.                 int     21h
  108.                 mov     di, 0Ah
  109.                 lea     si, EMM_name            ; Compare name
  110.                 mov     cx, EMM_name_length
  111.                 cld
  112.                 repe    cmpsb
  113.                 jne     not_installed           ; Not installed
  114.  
  115. EMM_installed:  mov     ax, 5401h               ; Check if handle exists
  116.                 mov     si, offset handle_name
  117.                 int     67h
  118.                 or      ah, ah                  ; Return OK?
  119.                 jnz     name_not_found          ; Yes, handle in dx
  120.  
  121. name_found:     mov     word ptr handle, dx     ; Store handle
  122.                 mov     ah, 4Ch                 ; Find # of pages owned
  123.                 int     67h
  124.                 mov     word ptr pages, bx      ; Store # of pages owned
  125.  
  126.                 clc                             ; Signal success
  127.                 jmp     check_EMM_exit          ; Exit!
  128.  
  129. not_installed:  mov     si, offset no_EMM_msg   ; EMM not found
  130.                 call    printf_si
  131.                 stc
  132.                 jmp     check_EMM_exit
  133.  
  134. name_not_found: mov     si, offset no_name_msg  ; Handle name not found
  135.                 call    printf_si
  136.                 stc
  137.  
  138. check_EMM_exit: ret
  139. check_EMM       ENDP
  140.  
  141.  
  142. check_MCB       PROC    near
  143.                 push    ds
  144.                 mov     ax, cs          ; Point to MCB for this blcok
  145.                 dec     ax
  146.                 mov     ds, ax
  147.                 mov     al, ds:0000     ; Retrieve first byte
  148.                 pop     ds
  149.                 cmp     al, 5Ah         ; 5Ah for last, 4Dh for not last
  150.                 jnz     not_last
  151.  
  152. is_last:        clc
  153.                 jmp     check_MCB_exit
  154.  
  155. not_last:       mov     si, offset not_last_msg
  156.                 call    printf_si
  157.                 stc
  158.  
  159. check_MCB_exit: ret
  160. check_MCB       ENDP
  161.  
  162.  
  163. tell_DOS        PROC    near
  164.                 push    ds
  165.                 mov     ax, ds                  ; Make sure ES=DS
  166.                 mov     es, ax
  167.  
  168. get_pages:      mov     ax, word ptr pages      ; # of pages added by ADDRAM
  169.                 mov     cl, 0Ah
  170.                 shl     ax, cl                  ; AX = # of paragraphs added
  171.  
  172.                 mov     dx, cs                  ; Address MCB
  173.                 dec     dx
  174.                 mov     ds, dx
  175.                 sub     ds:0003, ax             ; Change MCB
  176.                 sub     es:0002, ax             ; Change PSP
  177.  
  178.                 mov     cl, 6
  179.                 shr     ax, cl                  ; ax = KB added
  180.                 mov     dx, 40h
  181.                 mov     ds, dx
  182.                 sub     ds:0013, ax             ; Change BIOS
  183.  
  184.                 pop     ds
  185.  
  186.                 mov     si, offset mem_reset_msg
  187.                 call    printf_si
  188.                 clc
  189.  
  190. tell_DOS_exit:  ret
  191. tell_DOS        ENDP
  192.  
  193.  
  194. free_handle     PROC    near
  195.                 mov     ah, 45h                 ; Deallocate pages
  196.                 mov     dx, word ptr handle     ; Retrieve handle #
  197.                 int     67h
  198.                 or      ah, ah                  ; Error?
  199.                 jz      free_OK
  200.  
  201. free_fail:      mov     si, offset free_err_msg
  202.                 call    printf_si
  203.                 stc
  204.                 jmp     free_exit
  205.  
  206. free_OK:        clc
  207.  
  208. free_exit:      ret
  209. free_handle     ENDP
  210.  
  211.  
  212. printf_si       PROC    near
  213.                 mov     ah, 06h         ; DOS function 06h, console output
  214.  
  215. next_char:      lodsb                   ; Next char into al
  216.                 or      al, al          ; Is it zero?
  217.                 jz      printf_done     ; Yes, exit
  218.                 mov     dl, al          ; Put char into dl
  219.                 int     21h             ; Output character
  220.                 jmp     next_char       ; Loop to next character
  221.  
  222. printf_done:    ret
  223. printf_si       ENDP
  224.                 
  225. code_seg_a      ends
  226.  
  227.                 end     start
  228.  
  229.  
  230.  
  231.  
  232.